USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups-Insert]    Script Date: [[20120914064954]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064954]]
-- Description:	Insert record into table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Insert]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Insert]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Insert]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null  , 
	@Is_SystemGroup tinyint =0  , 
	@Group_TimeStamp timestamp =Null OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	INSERT  INTO [dbo].[Groups](/*[Group_ID], [Group_NameAr], [Group_NameEn], [Group_Search], [Is_SystemGroup]*/)
	VALUES     (/*@Group_ID, @Group_NameAr, @Group_NameEn, @Group_Search, @Is_SystemGroup*/)

	/*SELECT @Group_RowNumber = [Group_RowNumber], @Group_TimeStamp = [Group_TimeStamp]
    FROM [dbo].[Groups]
    WHERE  ( [Group_ID] =@Group_ID )
	AND  ( [Group_NameAr] =@Group_NameAr )
	AND  ( [Group_NameEn] =@Group_NameEn )
	AND  ( [Group_Search] =@Group_Search )
	AND  ( [Is_SystemGroup] =@Is_SystemGroup )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups-update]    Script Date: [[20120914064954]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064954]]
-- Description:	Update record in table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-update]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null  , 
	@Is_SystemGroup tinyint =0  , 
	@Group_TimeStamp timestamp =Null OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	/*SELECT @OldTimeStamp = [Group_TimeStamp]
    FROM [dbo].[Groups]
    	WHERE ([Group_ID] = @Group_ID)

    IF  @OldTimeStamp = @Group_TimeStamp
    BEGIN*/
		Update [dbo].[Groups] SET 
		/*[Group_ID] =@Group_ID, 
		[Group_NameAr] =@Group_NameAr, 
		[Group_NameEn] =@Group_NameEn, 
		[Group_Search] =@Group_Search, 
		[Is_SystemGroup] =@Is_SystemGroup*/
		/*WHERE ([Group_ID] = @Group_ID)*/
	/*END*/

	/*SELECT @Group_RowNumber = [Group_RowNumber], @Group_TimeStamp = [Group_TimeStamp]
    FROM [dbo].[Groups]
	WHERE ([Group_ID] = @Group_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups-Insert-Update]    Script Date: [[20120914064954]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064954]]
-- Description:	Insert OR Update record into table [dbo].[Groups]
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Insert-Update]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Insert-Update]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Insert-Update]
	/*@Group_RowNumber int =Null OUTPUT , 
	@Group_ID uniqueidentifier =Null  , 
	@Group_NameAr varchar(200) =Null  , 
	@Group_NameEn varchar(200) =Null  , 
	@Group_Search varchar(max) =Null  , 
	@Is_SystemGroup tinyint =0  , 
	@Group_TimeStamp timestamp =Null OUTPUT , 
	@Inserted bit OUTPUT , 
	@OldTimeStamp timeStamp OUTPUT*/ 
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;
	IF NOT EXISTS (SELECT * FROM [dbo].[Groups] 
					/*WHERE ([Group_ID] = @Group_ID)*/)
	BEGIN
		
		INSERT  INTO [dbo].[Groups](/*[Group_ID], [Group_NameAr], [Group_NameEn], [Group_Search], [Is_SystemGroup]*/)
		VALUES     (/*@Group_ID, @Group_NameAr, @Group_NameEn, @Group_Search, @Is_SystemGroup*/)

		SET /*@*/Inserted=1
	END
	ELSE
	BEGIN
		
		/*SELECT @OldTimeStamp = [Group_TimeStamp]
		FROM [dbo].[Groups]
    	WHERE ([Group_ID] = @Group_ID)

		IF  @OldTimeStamp = @Group_TimeStamp
		BEGIN*/
			Update [dbo].[Groups] SET 
			/*[Group_ID] =@Group_ID, 
			[Group_NameAr] =@Group_NameAr, 
			[Group_NameEn] =@Group_NameEn, 
			[Group_Search] =@Group_Search, 
			[Is_SystemGroup] =@Is_SystemGroup*/
			/*WHERE ([Group_ID] = @Group_ID)*/
		/*END*/
		
		SET /*@*/Inserted=0
	END

	/*SELECT @Group_RowNumber = [Group_RowNumber], @Group_TimeStamp = [Group_TimeStamp]
    FROM [dbo].[Groups]
	WHERE ([Group_ID] = @Group_ID)*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups-Delete]    Script Date: [[20120914064954]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064954]]
-- Description:	delete records from table [dbo].[Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Delete]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Delete]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Delete]
	/*@Group_RowNumber int =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Group_NameAr varchar(200) =null  , 
	@Group_NameEn varchar(200) =null  , 
	@Group_Search varchar(max) =null  , 
	@Is_SystemGroup tinyint =null  , 
	@Group_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	Delete FROM  [dbo].[Groups]
	WHERE /*( [Group_RowNumber] = ISNULL(@Group_RowNumber, [Group_RowNumber]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Group_NameAr] like ISNULL(@Group_NameAr, [Group_NameAr]) )
	AND ( [Group_NameEn] like ISNULL(@Group_NameEn, [Group_NameEn]) )
	AND ( [Group_Search] like ISNULL(@Group_Search, [Group_Search]) )
	AND ( [Is_SystemGroup] = ISNULL(@Is_SystemGroup, [Is_SystemGroup]) )
	AND ( [Group_TimeStamp] = ISNULL(@Group_TimeStamp, [Group_TimeStamp]) )*/
END
GO
-- =============================================
USE [CustomersSuppliers]
/****** Object:  StoredProcedure [dbo].[Groups-Select]    Script Date: [[20120914064954]] ******/
-- =============================================
-- Author:		Ahmed Fathi Hamouda Abd El Hafez
-- Create date: [[20120914064954]]
-- Description:	select records from table [dbo].[Groups] based on optional Conditions
-- =============================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
/*IF EXISTS (SELECT * FROM dbo.Sysobjects where id = object_id(N'[dbo].[Groups-Select]') AND OBJECTPROPERTY(id, N'IsProcedure') = 1)
   drop procedure [dbo].[Groups-Select]*/
GO
-- =============================================
Create PROCEDURE [dbo].[Groups-Select]
	/*@Group_RowNumber int =null  , 
	@Group_ID uniqueidentifier =null  , 
	@Group_NameAr varchar(200) =null  , 
	@Group_NameEn varchar(200) =null  , 
	@Group_Search varchar(max) =null  , 
	@Is_SystemGroup tinyint =null  , 
	@Group_TimeStamp timestamp =null*/
AS
BEGIN
	--SET NOCOUNT ON added to prevent extra result sets from
	--interfering with SELECT statements.
	SET NOCOUNT ON;

	SELECT * FROM  [dbo].[Groups]
	WHERE /*( [Group_RowNumber] = ISNULL(@Group_RowNumber, [Group_RowNumber]) )
	AND ( [Group_ID] = ISNULL(@Group_ID, [Group_ID]) )
	AND ( [Group_NameAr] like ISNULL(@Group_NameAr, [Group_NameAr]) )
	AND ( [Group_NameEn] like ISNULL(@Group_NameEn, [Group_NameEn]) )
	AND ( [Group_Search] like ISNULL(@Group_Search, [Group_Search]) )
	AND ( [Is_SystemGroup] = ISNULL(@Is_SystemGroup, [Is_SystemGroup]) )
	AND ( [Group_TimeStamp] = ISNULL(@Group_TimeStamp, [Group_TimeStamp]) )*/
END
GO
-- =============================================
